package com.markerhub.common.lang;

import lombok.Data;

import java.io.Serializable;

/**
 * @author cxz
 * 统一结果封装
 * @version 1.0
 */
@Data
public class Result  implements Serializable {
    private int code;
    private String msg;
    private Object data;

    /**
     * 进行一个封装，然后就是msg成功返回给前台其实也没什么用，主要用来定位报错信息
     * @param data
     * @return
     */
    public static Result success( Object data){


        return success(200,"操作成功",data);
    }
    public static Result success(int code, String msg, Object data){
        Result  result= new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);

        return result;
    }

    /**
     * 调用起来比较方便，失败信息，主要靠msg定位，data反而不重要
     * @param msg
     * @return
     */
    public static Result fail(String msg){
        return fail(400,msg,null);
    }
    public static Result fail( String msg, Object data){
        return fail(400,msg,data);
    }

    public static Result fail(int code, String msg, Object data){
        Result  result= new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);

        return result;
    }




}
